<?php
/**
 * Created by PhpStorm.
 * User: wanglei
 * Date: 2016/7/30
 * Time: 16:52
 */
defined('IN_PHPCMS') or exit('No permission resources.');
//模型缓存路径
define('CACHE_MODEL_PATH',CACHE_PATH.'caches_model'.DIRECTORY_SEPARATOR.'caches_data'.DIRECTORY_SEPARATOR);
pc_base::load_app_func('util','content');
pc_base::load_sys_class('form', '', 0);
class web {


    /**
     * 前台首页
     */
    public function init()
    {
        //提示栏
        $this->shuafen_tips = pc_base::load_model('shuafen_tips_model');
        $tips = $this->shuafen_tips->get_one();
        //轮播图片
        $this->shuafen_carousel = pc_base::load_model('shuafen_carousel_model');
        $carousel = $this->shuafen_carousel->select(array('is_show'=>'Y'));
        //限制次数和下载量
        $this->shuafen_download_times = pc_base::load_model('shuafen_download_times_model');
        $times = $this->shuafen_download_times->get_one();
        $where = "trash = 0  and add_user='Y'";
        //免费用户信息
        $this->member = pc_base::load_model('member_model');

        //首页显示免费用户个数
        $index_data_conf = $times['index_data_conf'];

        $infos = $this->member->select($where, '*', "0, $index_data_conf", 'start_time desc');
        $sex = array('0'=>'男','1'=>'女');
        $user_id= param::get_cookie('_userid',0);;
        include template('shuafen','index','default');
    }
    /**
     * 免费一键添加好友
     * 说明：只下载点击过被加好友按钮的用户 对应  后台的被加好友管理  里面只有置顶功能
    下载顺序：置顶的最前面，置顶里面有个start_time这个降序
     */
    public function free_add(){
        //是否是vip会员中心免费资源
        $is_vip = isset($_GET['vip'])?true:false;
        //限制次数和下载量
        $this->shuafen_download_times = pc_base::load_model('shuafen_download_times_model');
        $times = $this->shuafen_download_times->get_one();
        //免费加好友一次可以下载的数量
        $down_times = $is_vip?$times['free_down_times']:$times['free_add_down_times'];

        $where = "trash = 0  and add_user='Y'";
        $order = $is_vip?'free_top desc , free_top_time desc , userid desc':'top desc,start_time desc';


        //用户信息
        $this->member = pc_base::load_model('member_model');
        $infos = $this->member->select($where, '*', "0, $down_times",$order );
        if(!$infos){
           header("location:/index.php?m=shuafen&c=web");exit();
        }
        $this->common = pc_base::load_app_class('common');
        $this->common->downloadVcard('free_data',$infos);
    }
    /**
     * 退出登录
     */
    public function loginOut()
    {
        param::set_cookie('_userid',0);
//        showmessage(L('注销成功'),'?m=shuafen&c=web');
        header("location:/index.php?m=shuafen&c=web");exit();
    }
    /**
     * 登录
     */
    public function login()
    {
        if(isset($_POST['dosubmit'])) {
            $username = isset($_POST['username']) && is_username($_POST['username']) ? trim($_POST['username']) : showmessage(L('username_empty'), HTTP_REFERER);
            $password = isset($_POST['password']) && trim($_POST['password']) ? trim($_POST['password']) : showmessage(L('password_empty'), HTTP_REFERER);
            is_password($_POST['password']) && is_badword($_POST['password'])==false ? trim($_POST['password']) : showmessage(L('password_format_incorrect'), HTTP_REFERER);
            //查询帐号
            $member_model = pc_base::load_model('member_model');
            $r = $member_model->get_one(array('username'=>$username));
            if(!$r){
                $message = '用户名或密码错误';
                include template('shuafen','login','default');exit();
//                showmessage(L('user_not_exist'),'index.php?m=shuafen&c=web&a=login');
            }
            //验证用户密码
            $password = md5(md5(trim($password)).$r['encrypt']);
            if($r['password'] != $password) {
//                showmessage(L('password_error'), 'index.php?m=shuafen&c=web&a=login');
                $message = '用户名或密码错误';
                include template('shuafen','login','default');exit();
            }
            $cookietime = param::get_cookie('cookietime');
            $_cookietime = $cookietime ? intval($cookietime) :0;
            $cookietime = $_cookietime ? TIME + $_cookietime : 0;
            $userid = $r['userid'];
            $nickname = $r['nickname'];
            param::set_cookie('_userid', $userid, $cookietime);
            param::set_cookie('_username', $username, $cookietime);
            param::set_cookie('cookietime', $_cookietime, $cookietime);
            param::set_cookie('_nickname', $nickname, $cookietime);
//            showmessage(L('login_success'),'index.php?m=shuafen&c=web');
            header("location:/index.php?m=shuafen&c=web");exit();
        } else {
            include template('shuafen','login','default');
        }

    }
    /**
     * 注册
     */
    public function register()
    {
        if(isset($_POST['dosubmit'])) { //提交数据
            //启动session
            $session_storage = 'session_' . pc_base::load_config('system', 'session_storage');
            pc_base::load_sys_class($session_storage);
            //验证码
            if (($_SESSION['code'] != strtolower($_POST['code'])) || empty($_SESSION['code'])) {
//                showmessage("验证码错误");
                $message = '验证码错误';
                include template('shuafen','register','default');exit();
            } else {
                $_SESSION['code'] = '';
            }
            $userinfo = array();
            $userinfo['encrypt'] = create_randomstr(6);
//            print_r($_POST);die;
            $userinfo['username'] = (isset($_POST['telephone']) && is_username($_POST['telephone'])) ? $_POST['telephone'] : exit('0');
            $userinfo['nickname'] = (isset($_POST['nickname']) && is_username($_POST['nickname'])) ? $_POST['nickname'] : '';
            $userinfo['password'] = (isset($_POST['password']) && is_badword($_POST['password'])==false) ? $_POST['password'] : exit('0');
            $userinfo['password'] = password($userinfo['password'], $userinfo['encrypt']);
            $userinfo['province'] = $_POST['province'];
            $userinfo['city'] = $_POST['city'];
            $userinfo['industry_one'] = isset($_POST['industry_three'])?intval($_POST['industry_one']):0;
            $userinfo['industry_two'] = isset($_POST['industry_two'])?intval($_POST['industry_two']):0;
            $userinfo['industry_three'] = isset($_POST['industry_three'])?intval($_POST['industry_three']):0;
            $userinfo['security_question'] = $_POST['security_question'];
            $userinfo['security_answer'] = $_POST['security_answer'];
            $userinfo['img'] = $_POST['img'];
            $member_model = pc_base::load_model('member_model');
            $result = $member_model->insert($userinfo);
            if($result){
//                showmessage(L('注册成功'),'index.php?m=shuafen&c=web&a=login');
                header("location:/index.php?m=shuafen&c=web&a=login");exit();
            }else{
                $message = '注册失败';
                include template('shuafen','register','default');exit();
//                showmessage(L('注册失败'),'index.php?m=shuafen&c=weba=register');
            }
        }else{
            include template('shuafen','register','default');
        }

    }

    /**
     * 找回密码
     */
    public function findpwd(){
        if(isset($_POST['dosubmit'])) {
            $username = isset($_POST['username']) && is_username($_POST['username']) ? trim($_POST['username']) : showmessage(L('username_empty'), HTTP_REFERER);
            $security_question =$_POST['security_question'];
            $security_answer =$_POST['security_answer'];
            //查询帐号
            $member_model = pc_base::load_model('member_model');
            $r = $member_model->get_one(array('username'=>$username,'security_question'=>$security_question,'security_answer'=>$security_answer));
            if(!$r){
                $message = '密保答案不正确';
                include template('shuafen','findpwd','default');exit();
            }
            $password = password('123456', $r['encrypt']);
            $member_model->update(array('password'=>$password),array('username'=>$username,'security_question'=>$security_question,'security_answer'=>$security_answer));
            $message = '密保找回成功,重置为:123456<a class="btn btn-primary btn-lg btn-block" href="index.php?m=shuafen&c=web&a=login">点击登陆</a><br />';
            include template('shuafen','findpwd','default');exit();
//
//            $cookietime = param::get_cookie('cookietime');
//            $_cookietime = $cookietime ? intval($cookietime) :0;
//            $cookietime = $_cookietime ? TIME + $_cookietime : 0;
//            $userid = $r['userid'];
//            $nickname = $r['nickname'];
//            param::set_cookie('_userid', $userid, $cookietime);
//            param::set_cookie('_username', $username, $cookietime);
//            param::set_cookie('cookietime', $_cookietime, $cookietime);
//            param::set_cookie('_nickname', $nickname, $cookietime);
//            header("location:/index.php?m=shuafen&c=web");exit();
        } else {
            include template('shuafen','findpwd','default');
        }
    }
    /**
     * 检查用户时候存在
     */
    public function checkUsername()
    {
        $username = $_POST['username'];
        $member_model = pc_base::load_model('member_model');
        $result = $member_model->get_one(array('username'=>$username));
        if($result){
            echo json_encode(array(
                'valid' => false,
            ));
        }else{
            echo json_encode(array(
                'valid' => true,
            ));
        }
    }
    /**
     * 首页点击被动加好友
     */
    public function passivityAdd()
    {
        $user_id= param::get_cookie('_userid',0);
        if(!$user_id){
            header("location:/index.php?m=shuafen&c=web&a=login");exit();
        }

        $member_model = pc_base::load_model('member_model');
        $member = $member_model->get_one(array('userid'=>$user_id));
        if(!$member) header("location:/index.php?m=shuafen&c=web&a=login");exit();

        //被动加剩余次数
        $add_times = $member['add_times'];
        $click_add_times = $member['click_add_times '];
        if(!$add_times){
            echo json_encode(array('status'=>false,'msg'=>'排队次数不足，请通过会员中心->购买排队次数->购买！'));
        }else{
            //次数减一,点击次数加一，开始时间更新，
            $update_data = array(
                'add_times'=>$add_times-1,
                'click_add_times'=>$click_add_times+1,
                'start_time'=>time(),
                'add_user'=>'Y'
            );
            $result = $member_model->update($update_data,array('userid'=>$user_id));
            echo json_encode(array('status'=>true));
        }
    }
    /**
     * 行业类型分类
     */
    public function getIndustry()
    {
        $pid = isset($_GET['pid'])?intval($_GET['pid']):0;
        $shuafen_industry_model = pc_base::load_model("shuafen_industry_model");
        $data = $shuafen_industry_model->select("pid=".$pid);
        echo json_encode($data);
    }



    /**
     * 检查用户是否可以下载
     */
    public function check_download()
    {
        $user_id= param::get_cookie('_userid',0);
        if(!$user_id) {
            exit(json_encode(array('status'=>false,'msg'=>'您还没有登录，登录后才能下载！')));
        }
        $member_model = pc_base::load_model('member_model');
        $member = $member_model->get_one(array('userid'=>$user_id));

        //是否是vip
        if($member['vip']=='N'){
            exit(json_encode(array('status'=>false,'msg'=>'您还是VIP用户，不能使用此功能，充值即可升级为VIP用户！')));
        }
        //检查精确下载次数
        $exact_times =$member['exact_times'];
        if($exact_times<1){
            exit(json_encode(array('status'=>false,'msg'=>'您的精确下载次数不足，请先购买精确下载次数！')));
        }
        echo json_encode(array('status'=>true));
    }
    /**
     * 精确查找
     */
    public function search(){
        $user_id= param::get_cookie('_userid',0);
        if(!$user_id){
            header("location:/index.php?m=shuafen&c=web&a=login");exit();
        }
        $member_model = pc_base::load_model('member_model');
        $member = $member_model->get_one(array('userid'=>$user_id));
        if(!$member){
            header("location:/index.php?m=shuafen&c=web&a=login");exit();
        }
        include template('shuafen','search','default');
    }
    /**
     * 根据条件查找数据
     */
    public function do_search()
    {
        $user_id= param::get_cookie('_userid',0);
        if(!$user_id) {
            exit(json_encode(array('status'=>false,'msg'=>'您还没有登录，登录后才能查找！')));
        }
        $search = $this->do_search_where();
        $where = $search['where'];
        $is_svip = $search['is_svip'];
        $member_model = pc_base::load_model('member_model');



        $num = $member_model->count($where);
        //一次下载个数
        $this->shuafen_download_times = pc_base::load_model('shuafen_download_times_model');
        $times = $this->shuafen_download_times->get_one();

        $pagesize = $is_svip?$times['svip_down_times']:$times['vip_down_times'];
        $pagesize = $pagesize?$pagesize:10;
        echo json_encode(array('num'=>$num,'pagesize'=>$pagesize,'status'=>true));
    }
    private function do_search_where()
    {
        $user_id= param::get_cookie('_userid',0);
        $member_model = pc_base::load_model('member_model');
        //用户信息
        $member = $member_model->get_one(array('userid'=>$user_id));

        //判定用户等级 vip svip
        $where = "1=1 ";
        //性别
        if(isset($_POST['sex']) && $_POST['sex']!=-1){
            $where .= " and sex=".intval($_POST['sex']);
        }
        //省份
        if(isset($_POST['province']) && $_POST['province']){
            $where .= " and province='".$_POST['province']."'";
        }
        //城市
        if(isset($_POST['city']) && $_POST['city']){
            $where .= " and city='".$_POST['city']."'";
        }
        //一级行业
        if(isset($_POST['industry_one']) && $_POST['industry_one']){
            $where .= " and industry_one=".intval($_POST['industry_one']);
        }
        //二级行业
        if(isset($_POST['industry_two']) && $_POST['industry_two']){
            $where .= " and industry_two=".intval($_POST['industry_two']);
        }
        //三级行业
        if(isset($_POST['industry_three']) && $_POST['industry_three']){
            $where .= " and industry_three=".intval($_POST['industry_three']);
        }
        //如果是vip用户,svip没有限制
        if($member['vip']=='Y' && $member['svip']=='N'){
            $where .= " and vip='Y'";
        }

        return array(
            'where'=>$where,
            'is_svip'=>$member['svip']
        );
    }
    /**
     * 下载搜索的结果
     */
    public function do_search_download()
    {
        $member_model = pc_base::load_model('member_model');
        $search = $this->do_search_where();
        $where = $search['where'];
        $is_svip = $search['is_svip'];
        $order = $is_svip?"svip_top desc , svip_top_time desc , register_time desc":"vip_top desc , vip_top_time desc , vip_time desc";
        //开始位置
        $startPos = isset($_POST['startPos'])? intval($_POST['startPos']):0;
        $offset = $startPos-1?$startPos-1:0;
        $offset = $offset>=0 ?$offset : 0;
        //一次下载个数
        $this->shuafen_download_times = pc_base::load_model('shuafen_download_times_model');
        $times = $this->shuafen_download_times->get_one();

        $pagesize = $is_svip?$times['svip_down_times']:$times['vip_down_times'];
        $data = $member_model->select($where, '*', "$offset, $pagesize", $order);

        $this->common = pc_base::load_app_class('common');
        $this->common->downloadVcard('exact_data',$data);
    }
    /**
     * 新手教程
     */
    public function novice(){
        $this->shuafen_tutorial = pc_base::load_model('shuafen_tutorial_model');
        $tutorial = $this->shuafen_tutorial->get_one();
        include template('shuafen','novice','default');
    }

    /**
     * 会员中心
     */
    public function userCenter(){
        $user_id= param::get_cookie('_userid',0);
//        if(!$user_id) showmessage(L('请先登录'),'index.php?m=shuafen&c=web&a=login');
        if(!$user_id){
            header("location:/index.php?m=shuafen&c=web&a=login");exit();
        }
        $member_model = pc_base::load_model('member_model');
        $member = $member_model->get_one(array('userid'=>$user_id));
//        if(!$member) showmessage(L('用户不存在'),'index.php?m=shuafen&c=web&a=login');
        if(!$member){
            header("location:/index.php?m=shuafen&c=web&a=login");exit();
        }
        //用户类型
        $user_type = '普通';
        if($member['svip']=='Y'){
            $user_type = 'svip';
        }elseif($member['vip']=='Y'){
            $user_type = 'vip';
        }
        include template('shuafen','toUserCenter','default');
    }
    /**
     * 查看我的信息
     */
    public function myInfo(){
        $userid = param::get_cookie('_userid',0);
        if($userid){
            $industry_model = pc_base::load_model('shuafen_industry_model');
            $industry = $industry_model->select();
            foreach($industry as $k=>$v){
                $industrys[$v['id']] = $v;
            }
            $member_model = pc_base::load_model('member_model');
            $member = $member_model->get_one(array('userid'=>$userid));
            include template('shuafen','myInfo','default');
        }else{
            header("location:/index.php?m=shuafen&c=web&a=login");exit();
        }
    }
    /**
     * 修改我的信息
     */
    public function updateMyInfo()
    {
        $userid = param::get_cookie('_userid',0);
        if(!$userid){
            header("location:/index.php?m=shuafen&c=web&a=login");exit();
        }
        $member_model = pc_base::load_model('member_model');
        if(isset($_POST['dosubmit'])) { //提交数据
            $data = $_POST;
            unset($data['dosubmit'],$data['username']);
            $result = $member_model->update($data,array("userid"=>$userid));
            if($result){
                header("location:/index.php?m=shuafen&c=web&a=userCenter");exit();
            }else{
                $message = '修改失败';
                $member = $member_model->get_one(array('userid'=>$userid));
                include template('shuafen','updateMyInfo','default');exit();

            }
        }else{
            $member = $member_model->get_one(array('userid'=>$userid));
            include template('shuafen','updateMyInfo','default');
        }

    }

    /**
     *修改密码
     */
    public function updatePassword(){
        $userid = param::get_cookie('_userid',0);
        if(!$userid){
            header("location:/index.php?m=shuafen&c=web&a=login");exit();
        }
        if(isset($_GET['dosubmit'])) { //提交数据
            $member_model = pc_base::load_model('member_model');
            $member = $member_model->get_one(array('userid'=>$userid));
            if(empty($member)){
                exit(json_encode(array('iserror'=>true,'msg'=>'用户不存在')));
            }
            $old_password = password($_POST['password'], $member['encrypt']);
            if($old_password != $member['password'] ){
                exit(json_encode(array('iserror'=>true,'msg'=>'原密码不正确')));
            }
            $newpassword = password($_POST['newPassword'], $member['encrypt']);
            $member_model->update(array('password'=>$newpassword),array('userid'=>$userid));
            exit(json_encode(array('iserror'=>false,'msg'=>'修改密码成功')));
        }else{
            include template('shuafen','updatePassword','default');
        }
    }

    /**
     * 充值配置
     */
    public function recharge(){
        if(isset($_GET['submit'])) {
            $shuafen_recharge_conf = pc_base::load_model('shuafen_recharge_conf_model');
            $recharge_conf = $shuafen_recharge_conf->select(array('is_show'=>'Y'));
//            print_r($recharge_conf);die;
            echo json_encode($recharge_conf);
        }else{
            include template('shuafen','recharge','default');
        }
    }

    /**
     * 购买各种次数
     */
    public function buyTimes(){
        if(isset($_GET['submit'])) {
            $shuafen_buy_money_conf = pc_base::load_model('shuafen_buy_money_conf_model');
            switch($_POST['buyType']){
                case 'lineup':
                    $buy_money_conf = $shuafen_buy_money_conf->get_one(array('id'=>1));
                    $money = $buy_money_conf['money'];
                    break;
                case 'downtimes':
                    $buy_money_conf = $shuafen_buy_money_conf->get_one(array('id'=>2));
                    $money = $buy_money_conf['money'];
                    break;
                case 'searchtimes':
                    $buy_money_conf = $shuafen_buy_money_conf->get_one(array('id'=>3));
                    $money = $buy_money_conf['money'];
                    break;
            }
            $allmoney = $money*$_POST['totalTimes'];
            echo json_encode(array('message'=>$allmoney));
        }else{
            $type = $_GET['type'];
            include template('shuafen','buyDownloadTimes','default');
        }
    }

    /**
     * 支付购买的东西
     */
    public function dobuyTimes(){
        $shuafen_buy_money_conf = pc_base::load_model('shuafen_buy_money_conf_model');
        switch($_POST['buyType']){
            case 'lineup':
                $buy_money_conf = $shuafen_buy_money_conf->get_one(array('id'=>1));
                $money = $buy_money_conf['money'];
                $add = 'add_times';
                $goods_id = 1;
                $goods_name = '购买被动次数金额';
                break;
            case 'downtimes':
                $buy_money_conf = $shuafen_buy_money_conf->get_one(array('id'=>2));
                $money = $buy_money_conf['money'];
                $add = 'down_times';
                $goods_id = 2;
                $goods_name = '购买普通下载次数金额';
                break;
            case 'searchtimes':
                $buy_money_conf = $shuafen_buy_money_conf->get_one(array('id'=>3));
                $money = $buy_money_conf['money'];
                $add = 'exact_times';
                $goods_id = 3;
                $goods_name = '购买精确下载次数金额';
                break;
        }
        $allmoney = $money*$_POST['totalTimes'];
        $userid = param::get_cookie('_userid',0);
        $member_model = pc_base::load_model('member_model');
        $member = $member_model->get_one(array('userid'=>$userid));
        if($member['amount'] < $allmoney){
            exit(json_encode(array('iserror'=>1,'message'=>'余额不足')));
        }
        $addsql = 'UPDATE sjk_member SET '.$add.'='.$add.'+'.$_POST['totalTimes'].', amount=amount-'.$allmoney.' where userid = '.$userid;
        $addtimes = $member_model->query($addsql);
        if(!$addtimes){
            exit(json_encode(array('iserror'=>1,'message'=>'购买失败')));
        }
        //增加购买记录
        $buy_record = pc_base::load_model('shuafen_buy_record_model');
        $data['member_id'] = $userid;
        $data['member_tel'] = $member['username'];
        $data['goods_id'] = $goods_id;
        $data['goods_name'] = $goods_name;
        $data['times'] = $_POST['totalTimes'];
        $data['money'] = $allmoney;
        $data['time'] = time();
        $buy_record->insert($data);
        exit(json_encode(array('message'=>'购买成功')));
    }

    public function transfer(){
        include template('shuafen','transfStep1','default');
    }
    public function transfer2(){
        $member_model = pc_base::load_model('member_model');
        $userid = param::get_cookie('_userid',0);
        $member = $member_model->get_one(array('username'=>$_POST['mobile']));
        $shuafen_download_times = pc_base::load_model('shuafen_download_times_model');
        $lowTransfer = $shuafen_download_times->get_one();
        if(empty($userid) || !$userid){
            $message = '非法操作';
            include template('shuafen','transfStep2','default');exit();
        }
        if(isset($_GET['submit'])) {
            $frommember = $member_model->get_one(array('userid'=>$userid));
            if($frommember['amount'] < $_POST['transfMoney']){
                $message = '余额不足';
                include template('shuafen','transfStep2','default');exit();
            }
            if($_POST['toTel'] == $member['username']){
                //执行转账操作
                //更新转账方被转账方
                $upsql1 = 'UPDATE sjk_member SET  amount=amount-'.$_POST['transfMoney'].' where userid = '.$userid;
                $upMoney1 = $member_model->query($upsql1);
                if(!$upMoney1){
                    $message = '转账失败';
                    include template('shuafen','transfStep2','default');exit();
                }
                $upsql2 = 'UPDATE sjk_member SET  amount=amount+'.$_POST['transfMoney'].' where userid = '.$member['userid'];
                $upMoney2 = $member_model->query($upsql2);
                if(!$upMoney2){
                    $message = '转账失败';
                    include template('shuafen','transfStep2','default');exit();
                }
                $message = '转账成功';
                //判断被转账方余额是否满足条件成为VIP用户
                $shuafen_buy_money_conf = pc_base::load_model('shuafen_buy_money_conf_model');
                $is_vip = $shuafen_buy_money_conf->get_one(array('id'=>5));
                if(($member['amount'] + $_POST['transfMoney']) > $is_vip['money']){
                    $upsql3 = 'UPDATE sjk_member SET  vip = "Y" where userid = '.$member['userid'];
                    $upVip = $member_model->query($upsql3);
                }
            }else{
                $message = '非法操作';
            }
            include template('shuafen','transfStep2','default');
        }else{
            include template('shuafen','transfStep2','default');
        }
    }

    public function buySvip(){
        $shuafen_buy_money_conf = pc_base::load_model('shuafen_buy_money_conf_model');
        $message = $shuafen_buy_money_conf->get_one(array('id'=>4));
        $userid = param::get_cookie('_userid',0);
        $member_model = pc_base::load_model('member_model');
        $member = $member_model->get_one(array('userid'=>$userid));
        if($member['svip'] == 'Y'){
            echo json_encode(array('iserror'=>1,'message'=>'您已是svip用户,无需再次购买'));exit();
        }
        if(isset($_GET['submit'])) {
            if($member['amount'] < $message['money']){
                exit(json_encode(array('iserror'=>1,'message'=>'余额不足')));
            }
            $sql = 'UPDATE sjk_member SET  svip = "Y",amount=amount-'.$message['money'].' where userid = '.$userid;
            $upSVip = $shuafen_buy_money_conf->query($sql);
            if($upSVip){
                exit(json_encode(array('message'=>'购买成功')));
            }else{
                exit(json_encode(array('iserror'=>1,'message'=>'购买失败')));
            }
        }else{
            echo json_encode(array('message'=>$message['money']));
        }
    }
}